import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AuthResult, UserForm, UserPageVO, UserQuery } from './types';

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getAuthData(): AxiosPromise<AuthResult> {
  return request({
    url: 'base/auth/getAuthData',
    method: 'get',
  });
}

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(queryParams: UserQuery): AxiosPromise<PageResult<UserPageVO[]>> {
  return request({
    url: '/base/user/list',
    method: 'post',
    data: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function findUserById(userId: String): AxiosPromise<UserForm> {
  return request({
    url: 'base/user/findById',
    method: 'get',
    params: {
      id: userId,
    },
  });
}

/**
 * 添加用户
 *
 * @param data
 */
export function saveUser(data: any) {
  return request({
    url: '/base/user/save',
    method: 'post',
    data: data,
  });
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(id: string, password: string) {
  return request({
    url: '/api/v1/users/' + id + '/password',
    method: 'patch',
    params: { password: password },
  });
}
/**
 * 重置用户密码
 *
 * @param id
 */
export function resetPassword(id: string, isLoading: boolean) {
  return request({
    url: '/base/user/resetPassword',
    isLoading: isLoading,
    method: 'post',
    data: { id: id },
  });
}

/**
 * 删除用户
 *
 * @param ids
 */
export function deleteUsers(ids: string[], isLoading: boolean) {
  return request({
    url: '/base/user/delete',
    method: 'post',
    isLoading: isLoading,
    data: {
      ids: ids,
    },
  });
}
